/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            accountBondObjManageInfo: {
                accountBondObjs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                bobjId: '',
                receivableAmount: '',
                codeUrl: '',
                accountBondObjDetails: [],
                conditions: {
                    objId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listAccountBondObjs(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('accountBondObjManage', 'listAccountBondObj', function (_param) {
                $that._listAccountBondObjs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAccountBondObjs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAccountBondObjs: function (_page, _rows) {
                $that.accountBondObjManageInfo.conditions.page = _page;
                $that.accountBondObjManageInfo.conditions.row = _rows;
                let param = {
                    params: $that.accountBondObjManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/accountBondObj/queryAccountBondObj',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.accountBondObjManageInfo.total = _json.total;
                        $that.accountBondObjManageInfo.records = _json.records;
                        $that.accountBondObjManageInfo.accountBondObjs = _json.data;
                        if (_json.data.length > 0) {
                            $that.accountBondObjManageInfo.bobjId = _json.data[0].bobjId;
                            $that.accountBondObjManageInfo.receivableAmount = _json.data[0].receivableAmount;
                        }

                        vc.emit('pagination', 'init', {
                            total: $that.accountBondObjManageInfo.records,
                            dataCount: $that.accountBondObjManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listAccountBondObjDetails: function (_page, _rows) {
                let param = {
                    params: {
                        page: _page,
                        row: _rows,
                        bobjId: $that.accountBondObjManageInfo.bobjId
                    }
                };
                //发送get请求
                vc.http.apiGet('/accountBondObjDetail/queryAccountBondObjDetail',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.accountBondObjManageInfo.total = _json.total;
                        $that.accountBondObjManageInfo.records = _json.records;
                        $that.accountBondObjManageInfo.accountBondObjDetails = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.accountBondObjManageInfo.records,
                            dataCount: $that.accountBondObjManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryAccountBondObjMethod: function () {
                $that._listAccountBondObjs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.accountBondObjManageInfo.moreCondition) {
                    $that.accountBondObjManageInfo.moreCondition = false;
                } else {
                    $that.accountBondObjManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
